<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<style>
    .usual {
    }

    .fulled {
        color: red;
    }
</style>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约设置</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约设置</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="box ordersetting">
                <el-card class="box-card">
                    <div class="boxMain">
                        <el-button style="margin-bottom: 20px;margin-right: 20px" type="primary"
                                   @click="downloadTemplate()">模板下载
                        </el-button>
                        <el-upload action="/ordersetting/upload.do"
                                   name="excelFile"
                                   :show-file-list="false"
                                   :on-success="handleSuccess"
                                   :before-upload="beforeUpload">
                            <el-button type="primary">上传文件</el-button>
                        </el-upload>
                        <el-button type="primary" class="butT" @click="handleCreate()">电话预约</el-button>
                    </div>
                    <div>
                        操作说明：请点击"模板下载"按钮获取模板文件，在模板文件中录入预约设置数据后点击"上传文件"按钮上传模板文件。
                    </div>
                    <div class="add-form">
                        <el-dialog title="客户信息" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="电话号码">
                                                        <el-input v-model="formData.phoneNumber"
                                                                  type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="身份证">
                                                        <el-input v-model="formData.idCard"
                                                                  type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <div class="block">
                                                <span class="demonstration">预约时间</span>
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        value-format="yyyy-MM-dd"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </div>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐编码</th>
                                                    <th>套餐名称</th>
                                                    <th>套餐说明</th>
                                                    <th>套餐价格</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="checkgroupIds" type="checkbox"
                                                               :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.code}}</label></td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                    <td><label :for="c.id">{{c.price}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </el-card>
                <div class="calendar">

                    <el-calendar ref="settingCalendar" v-model="calendarValue">
                        <template slot="dateCell" slot-scope="{date, data}">
                            <!--                                date 代表当前格子的日期-->
                            {{date.getMonth() + 1}}-{{date.getDate()}}

                            <!-- 格子日期大于当前日期才有设置按钮 -->
                            <i v-if="date > today" class="el-icon-edit" @click="handleOrderSet(date)"></i>
                            <br>
                            <template v-for="item in leftobj">

                                <template v-if="date.getDate() == item.date && date.getMonth() == item.mouth">
                                    <template v-if="item.number > item.reservations">
                                        <div class="usual">
                                            <p>可预约{{item.number}}人</p>
                                            <p>已预约{{item.reservations}}人</p>
                                        </div>
                                    </template>
                                    <template v-else>
                                        <div class="fulled">
                                            <p>约满</p>
                                        </div>
                                    </template>
                                </template>
                            </template>
                        </template>
                    </el-calendar>

                </div>


            </div>

        </div>
    </div>

</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            today: new Date(),//当前日期
            leftobj: [],//用于装载页面显示的月份已经进行预约设置的数据
            calendarValue: '',//日历当前的value
            dialogFormVisible: false,
            formData: {},
            tableData: [],
            checkgroupIds: [],
            activeName: 'first',
            value1: '',

        },
        mounted: function () {
            this.initData(null);
        },
        methods: {
            //日历
            data() {
                return {
                    pickerOptions: {
                        disabledDate(time) {
                            return time.getTime() > Date.now();
                        }
                    },
                    value1: '',
                }
            },
            //预约提交
            handleAdd() {
                this.formData.checkgroupIds = this.checkgroupIds;
                console.log(this.formData);
                axios.post("/ordersetting/phoneSetOrderSetting.do", this.formData).then((res) => {
                    this.dialogFormVisible = false
                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? 'success' : "error" //success/warning/info/error
                    });
                })
            },
            //表单重置
            resetForm() {
                this.value1='';
                this.activeName = "first";
                this.formData = {};
                this.checkitemIds = [];//一定要赋值空数组 []
            },
            //电话预约
            handleCreate() {
                this.resetForm()
                this.dialogFormVisible = true
                axios.get("/ordersetting/findOrder.do").then((res) => {
                    // res.data = {flag,message,data}
                    this.tableData = res.data.data;
                })
            },
            //预约设置
            handleOrderSet(date) {
                // getDate()	从 Date 对象返回一个月中的某一天 (1 ~ 31)。
                // getDay()	从 Date 对象返回一周中的某一天 (0 ~ 6)。
                // getMonth()	从 Date 对象返回月份 (0 ~ 11)。
                // getFullYear()	从 Date 对象以四位数字返回年份。
                this.$prompt('请输入可预约人数', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /(^[1-9]\d*$)/,
                    inputErrorMessage: '请输入正整数'
                }).then(({value}) => {
                    var param = {
                        orderDate: this.formatDate(date.getFullYear(), (date.getMonth() + 1), date.getDate()),
                        number: value
                    }

                    axios.post("/ordersetting/setNumberByDate.do", param).then((res) => {
                        //提示用户

                        //刷新页面
                        this.initData(date)
                    })


                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消输入'
                    });
                });

            },
            initData: function (date) {
                console.log(date);
                if (!date) {
                    //获取日历对象
                    let settingCalendar = this.$refs.settingCalendar;
                    //获取当前时间
                    date = settingCalendar.date;
                }

                let formatDate = date.getFullYear() + "-" + (date.getMonth() + 1);//2020-1

                if (date.getMonth() < 10) {
                    formatDate = date.getFullYear() + "-0" + (date.getMonth() + 1)
                }

                console.log(formatDate);
                // this.leftobj = [
                //     {"date":22,"mouth":0,"number":300,"reservations":300,},
                //     {"date":23,"mouth":0,"number":300,"reservations":10,},
                //     {"date":24,"mouth":0,"number":300,"reservations":15,},
                //     {"date":25,"mouth":0,"number":300,"reservations":100,},
                //     {"date":26,"mouth":0,"number":300,"reservations":150,},
                //     {"date":27,"mouth":0,"number":300,"reservations":1,},
                // ]


                axios.post("/ordersetting/findByMonth.do", {mm: formatDate}).then((res) => {
                    this.leftobj = res.data.data;
                })

            },
            // 返回 类似 2016-01-02 格式的字符串
            formatDate: function (year, month, day) {
                var y = year;
                var m = month;
                if (m < 10) m = "0" + m;
                var d = day;
                if (d < 10) d = "0" + d;
                return y + "-" + m + "-" + d
            },				//上传之前进行文件格式校验
            beforeUpload(file) {
                // const isXLS = file.type === 'application/vnd.ms-excel';
                // if(isXLS){
                //     return true;
                // }
                // const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                // if (isXLSX) {
                //     return true;
                // }
                // this.$message.error('上传文件只能是xls或者xlsx格式!');
                return true;
            },
            //下载模板文件
            downloadTemplate() {
                window.location.href = "../../template/ordersetting_template.xlsx";
                // window.location.href = "http://www.baidu.com"
            },
            //上传成功提示
            handleSuccess(response, file) {
                if (response.flag) {
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                } else {
                    this.$message.error(response.message);
                }
                console.log(response, file, fileList);
            },
            //初始化当前页要展示的日期
        },
        watch: {
            //当点击上月 下月 当前月触发
            calendarValue(newVal, oldVal) {
                this.initData(newVal);
            }
        }
    })
</script>


</html>
